package com.fenfen.novel.utils;

import java.text.DecimalFormat;
import java.util.ArrayList;

public class NovelFileCallbackListener {
  private boolean isShowCost = false;
  private long start;
  private long end;
  private String cost;

  public NovelFileCallbackListener() {
    initTime();
  }

  private void initTime() {
    start = System.currentTimeMillis();
  }

  public NovelFileCallbackListener(boolean isShowCost) {
    this.isShowCost = isShowCost;
    if (isShowCost) {
      initTime();
    }
  }

  private void onFinish() {
    end = System.currentTimeMillis();
    float time = (end - start) / 1000f;
    DecimalFormat df = new DecimalFormat("0.00");
    cost = df.format(time);
  }

  public void onChapterListFinish(ArrayList<String> chapterTitleList) {
    if (isShowCost) {
      onFinish();
    }
  }

  public String getCost() {
    return cost;
  }

  public void onChapterContentFinish(String chapterContent, String title) {
    if (isShowCost) {
      onFinish();
    }
  }
}
